feat(cache): add cache token audit logging behind OPENCODE_EXPERIMENTAL_CACHE_AUDIT#27007
feat(cache): add cache token audit logging behind OPENCODE_EXPERIMENTAL_CACHE_AUDIT#27007martinffx wants to merge 2 commits into
Conversation
|
Hey! Your PR title Please update it to start with one of:
Where See CONTRIBUTING.md for details. |
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
efd4a32 to
f6b1ccd
Compare
…NCODE_CACHE_AUDIT Co-authored-by: Bhagirathsinh Vaghela <bhagirathsinh.vaghela.001@gmail.com>
f6b1ccd to
c186e10
Compare
|
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
Issue for this PR
Closes #5416, #5224
Related: #14065, #5422, #14203, #14743
Part of the stacked PR decomposition of the prompt caching fix (1 of 4). Adds cache token audit logging as observability foundation, the metrics logged here are what we use to verify cache hit improvements in subsequent PRs.
Type of change
What does this PR do?
Adds cache token audit logging behind
OPENCODE_EXPERIMENTAL_CACHE_AUDIT=1, providing per-LLM-call cache hit/miss visibility. This PR is purely observability — it does not change any caching behavior.Changes:
packages/core/src/flag/flag.ts— addsOPENCODE_EXPERIMENTAL_CACHE_AUDITflag.packages/opencode/src/session/session.ts— addsrawInputTokensto the usage return value (sum of input + cache read + cache write), needed by both the log and sidebar display.packages/opencode/src/session/processor.ts— after each LLM call'sgetUsage(), if the flag is set, logs a[CACHE]line with total input tokens, cache read/write/new breakdown, hit percentage, and output tokens.packages/opencode/src/cli/cmd/tui/feature-plugins/sidebar/context.tsx— when the flag is set, displays a "Cache Audit" box in the TUI sidebar showing the same token breakdown and hit rate in real time.Why this PR first: The subsequent PRs in the stack improve cache hit rates. This PR provides the measurement tooling to verify those improvements work.
How did you verify your code works?
Set
OPENCODE_EXPERIMENTAL_CACHE_AUDIT=1 bun dev, send a prompt, and confirm:[CACHE]log line appears per LLM call in the log outputTests:
bun test packages/opencode/test/session/session.test.tspasses.Screenshots
Checklist
Co-authored-by: Bhagirathsinh Vaghela bhagirathsinh.vaghela.001@gmail.com